//
//  QuestionsViewController.swift
//  AmountBody
//
//  Created by Qiu Jishuai on 2018/1/26.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

import UIKit

class QuestionsViewController: UIViewController {

    lazy var scrollView: UIScrollView = {
        let scrollView = UIScrollView()
        scrollView.delegate = self
        return scrollView
    }()

    let containerView = UIView()

    let testTexts = ["配件", "西服文化", "售后", "工艺展示", "工艺代码", "配件", "西服文化", "售后", "工艺展示", "工艺代码", "呵呵"]

    lazy var typeRulerView: RulerView = {
        let rulerView = RulerView()
        rulerView.items = ["配件", "西服文化", "售后", "工艺展示", "工艺代码", "配件", "西服文化", "售后", "工艺展示", "工艺代码", "呵呵"]
        rulerView.unitWidth = 10
        rulerView.currentIndex = 3
        rulerView.scrollableUnitCount = 20
        rulerView.shortLineHeightScale = 0
        rulerView.selectedCompletion = { (index, title) in
            self.typeFooter.title = title
        }
        return rulerView
    }()
    
    lazy var techniqueRulerView: RulerView = {
        let rulerView = RulerView()
        rulerView.items = ["配件", "西服文化", "售后", "工艺展示", "工艺代码", "配件", "西服文化", "售后", "工艺展示", "工艺代码", "呵呵"]
        rulerView.unitWidth = 10
        rulerView.scrollableUnitCount = 20
        rulerView.shortLineHeightScale = 0
        rulerView.selectedCompletion = { (index, title) in
            self.techniqueFooter.title = title
        }
        return rulerView
    }()

    let typeFooter: HeadlineView = {
        let footer = HeadlineView()
        footer.label.text = "西服工艺"
        return footer
    }()

    let techniqueFooter: HeadlineView = {
        let footer = HeadlineView()
        footer.label.text = "工艺展示"
        return footer
    }()

    let listView: HorizontalTextsListsView = {
        let listView = HorizontalTextsListsView()
        listView.layer.cornerRadius = 8
        listView.backgroundColor = UIColor(hexString: "#f4f4f4")
        return listView
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white
        title = "问题中心"

        view.addSubview(scrollView)
        scrollView.addSubview(containerView)
        containerView.addSubview(typeRulerView)
        containerView.addSubview(typeFooter)
        containerView.addSubview(techniqueRulerView)
        containerView.addSubview(techniqueFooter)
        containerView.addSubview(listView)

        scrollView.mas_makeConstraints({ (make) in
            make?.edges.width().height().equalTo()(view)
        })

        containerView.mas_makeConstraints({ (make) in
            make?.edges.width().height().equalTo()(scrollView)
        })

        typeRulerView.mas_makeConstraints { (make) in
            make?.left.right().equalTo()(containerView)
            make?.top.equalTo()(containerView)?.offset()(40)
            make?.height.equalTo()(80)
        }

        typeFooter.mas_makeConstraints { (make) in
            make?.centerX.equalTo()(containerView)
            make?.top.equalTo()(typeRulerView.mas_bottom)?.offset()(40)
        }

        techniqueRulerView.mas_makeConstraints { (make) in
            make?.left.right().equalTo()(containerView)
            make?.top.equalTo()(typeFooter.mas_bottom)?.offset()(40)
            make?.height.equalTo()(80)
        }

        techniqueFooter.mas_makeConstraints { (make) in
            make?.centerX.equalTo()(containerView)
            make?.top.equalTo()(techniqueRulerView.mas_bottom)?.offset()(40)
        }

        listView.mas_makeConstraints { (make) in
            make?.left.equalTo()(containerView)?.offset()(30)
            make?.right.equalTo()(containerView)?.offset()(-30)
            make?.top.equalTo()(techniqueFooter.mas_bottom)?.offset()(40)
        }

        listView.texts = {
            var texts: [String] = []
            for _ in 0...(5 + arc4random_uniform(10)) {
                var str = ""
                for _ in 0...(2 + arc4random_uniform(10)) {
                    str += "问题"
                }
                texts.append(str)
            }
            return texts
        }()

//        typeRulerView.setItem("售后", animated: false)
//        techniqueRulerView.setItem("售后", animated: false)
    }
}

extension QuestionsViewController: UIScrollViewDelegate {

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {

    }

    func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {

    }

    func scrollViewDidScroll(_ scrollView: UIScrollView) {

    }
}
